import { getAreaObj, uploadType } from '@/utils/util'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '留样日期',
			prop: 'sampleTime',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			span: 12,
			rules: [{ required: true, message: '请选择留样日期' }],
		},
		{
			label: '留样时间段',
			prop: 'meal',
			propName: 'mealLabel',
			type: 'select',
			dicData: [
				{
					label: '早餐',
					value: '0',
				},
				{
					label: '午餐',
					value: '1',
				},
				{
					label: '晚餐',
					value: '2',
				},
			],
			rules: [{ required: true, message: '请选择留样时间段' }],
			span: 12,
		},
		{
			label: '留样内容',
			prop: 'sampleName',
			type: 'textarea',
			maxlength: '500',
			showWordLimit: true,
			autosize: {
				minRows: 1,
			},
			span: 24,
			rules: [{ required: true, message: '请输入留样内容' }],
		},

		{
			label: '留样图片',
			prop: 'samplePhoto',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			changeField: true,
			span: 24,
		},
		{
			label: '签字照片',
			tip: '',
			prop: 'signature',
			type: 'upload',
			labelPosition: 'top',
			showFileList: false,
			limit: 1,
			multiple: false,
			span: 24,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '留样日期', prop: 'sampleTime' },
		{ label: '上传时间', prop: 'createTime' },
		{ label: '留样时间段', prop: 'mealLabel' },
		{ label: '留样内容', prop: 'sampleName' },
		{ label: '留样人', prop: 'createUserName' },
		{ label: '留样图片', prop: 'samplePhoto', custome: 'file' },
		{
			label: '操作',
			prop: 'menu',
			width: 100,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_smFoodSamples_page',
}
export const baseConfig = {
	pageName: '食品留样',
	dictcodes: [],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'sampleTime',
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		...api,
	},
	paramsObj: {
		source: 1,
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		},
	],
	beforeOnLoadFormate: async (params) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(params.areas)
			resolve({
				...params,
				...areaObj,
				areas: undefined,
			})
		})
	},
	dialogConfig: {
		width: '55%',
	},
	formConfig,
	tableConfig,
	detailConfig: formConfig,
}
